<?php 
require_once 'init.php';
require_once 'ckLogin.php';
require_once 'dbClasses'.DIRECTORY_SEPARATOR.'config.php';
require_once 'dbClasses'.DIRECTORY_SEPARATOR.'dbConn.php';
//
//require_once 'insertNewFunction.php';

$db = new dbConn();
//定义表名
define("TABLENAME","zz_extend_exchangegoods");
//图片路径
define("KEYWOED","exchangegoods");
if(strtoupper($_SERVER['REQUEST_METHOD'])=='POST'){
	//url name pic pirce ww pDate
	$url = str_replace(' ', '', trim($_POST['url']));
	$name = $_POST['name'];
	if (!empty($_POST['pic2'])) {
		$pic = $_POST['pic2'];
	}elseif (!empty($_POST['pic'])){
		$pic = 'http://app100656353.imgcache.qzoneapp.com/app100656353/'.KEYWOED.'/'.$_POST['pic'];
	}else {
		exit("图片不能为空，请后退后操作");
	}
	$pirce = $_POST['pirce'];
	$ww = $_POST['ww'];
	$pDate = $_POST['pDate'];
	$pwd = trim(generate_password());
	$exchangeGold = (int)$_POST['exchangeGold'];
	$exchangeNum  = (int)$_POST['exchangeNum'];
	$guanzhu = rand(1099, 3999);
	$db->sql = "INSERT INTO ".TABLENAME."(url,`name`,pic,pirce,ww,pDate,pwd,exchangeGold,exchangeNum,exchangeNumTol,guanzhu) VALUES('{$url}','{$name}','{$pic}',$pirce,'{$ww}','{$pDate}','{$pwd}',{$exchangeGold},{$exchangeNum},{$exchangeNum},{$guanzhu})";
	$db->doExecute();
	$rs = 1;
}

//echo generate_password();
function generate_password( $length = 8 ) {
	$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
	$password = '';
	for ( $i = 0; $i < $length; $i++ ){
		$password .= $chars[ mt_rand(0, strlen($chars) - 1) ];
	}
	return $password;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo APPLICATION;?></title>
<!--                       CSS                       -->
<!-- Reset Stylesheet -->
<link rel="stylesheet" href="resources/css/reset.css" type="text/css" media="screen" />
<!-- Main Stylesheet -->
<link rel="stylesheet" href="resources/css/main.css" type="text/css" media="screen" />
<!-- Invalid Stylesheet. This makes stuff look pretty. Remove it if you want the CSS completely valid -->
<link rel="stylesheet" href="resources/css/invalid.css" type="text/css" media="screen" />

<!-- jQuery -->
<script type="text/javascript" src="resources/scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(function($) {
	$(".showPic").click(function(){
		var pic_val = $(this).siblings("input").val();
		
		if(!pic_val || pic_val=="示例 : 2013-03-02/9932384376.jpg ----- cdn服务器上图片"){
			alert("图片不能为空！");
		}else{
			var _type = $(this).siblings("input").data("type");
			var _span_html = _type==2?("<img src='"+pic_val+"' style='width:100px;'/>地址："+pic_val):("<img src='http://app100656353.imgcache.qzoneapp.com/app100656353/<?php echo KEYWOED;?>/"+pic_val+"' style='width:100px;'/>地址：http://app100656353.imgcache.qzoneapp.com/app100656353/<?php echo KEYWOED;?>/"+pic_val);
			$(this).siblings("span").html('').append(_span_html);
		}
		//alert("fff");
	});
	$("input[name='pic'],input[name='pic2']").focus(function(){
		//if($(this).val()){
		$(this).val('');
		//}
		$(this).unbind( "focus" )
	});
});
</script>
<!-- jQuery Configuration -->
<script type="text/javascript"
	src="resources/scripts/simpla.jquery.configuration.js"></script>
<!-- Facebox jQuery Plugin -->
<script type="text/javascript" src="resources/scripts/facebox.js"></script>
<!-- jQuery WYSIWYG Plugin -->
<script type="text/javascript" src="resources/scripts/jquery.wysiwyg.js"></script>
<script type="text/javascript" src="resources/scripts/My97DatePicker/WdatePicker.js"></script>

</head>

<body>
	<div id="body-wrapper">
		<!-- Wrapper for the radial gradient background -->
		
		<div id="main-content">
			<!-- Page Head -->
			<h2>欢迎使用<?php echo APPLICATION;?>管理后台</h2>
			<p id="page-intro">竞拍添加&nbsp;&nbsp;&nbsp;<span style="color: red;">上传文件目录示例<?php echo KEYWOED;?>/日期（必须大于等于当前日期）/***.jpg(.png、……)</span></p>

			<div class="clear"></div>
			<!-- End .clear -->

			
			<div class="content-box">
				<!-- Start Content Box -->
				<div class="content-box-header">
					<h3>添加竞拍商品</h3>
					<div class="clear"></div>
				</div>
				<!-- End .content-box-header -->
				<div class="content-box-content">
				<?php if (isset($rs)):if ($rs==1)?>
					<div class="notification success png_bg" style="">
						<a href="#" class="close"><img
							src="resources/images/icons/cross_grey_small.png"
							title="Close this notification" alt="close" /></a>
						<div>
							添加成功
						</div>
					</div>
				<?php endif;?>
					
						
					<div class="tab-content default-tab" id="tab1">
						<!-- This is the target div. id must match the href of this div's tab -->
						<form action="#" method="post">
							<fieldset>
							<table>
								<tr>
									<td class="tr-td1" style="width: 100px;">商品链接：</td>
									<td><input class="text-input medium-input" type="text" name="url" style=""/></td>
								</tr>
								<tr>
									<td>商品名称：</td>
									<td><input class="text-input medium-input" type="text" name="name" style=""/></td>
								</tr>
								<tr>
									<td colspan="2">商品图片1、商品图片2任选一个即可,若两者都有优先图片2地址</td>
								</tr>
								<tr>
									<td>商品图片1：</td>
									<td><input class="text-input medium-input" type="text" name="pic" value="" data-type="1"/>&nbsp;&nbsp;<a href="javascript:;" class="showPic">显示图片</a><br /><span></span><p style="color: gray;">示例 : 2013-03-02/9932384376.jpg ----- cdn服务器上图片</p></td>
								</tr>
								<tr>
									<td>商品图片2：</td>
									<td><input class="text-input medium-input" type="text" name="pic2" value="" data-type="2"/>&nbsp;&nbsp;<a href="javascript:;" class="showPic">显示图片</a><br /><span></span><p style="color: gray;">示例 : http://img03.taobaocdn.com/bao/uploaded/i3/14216019580516677/T1B9U.XlpeXXXXXXXX_!!0-item_pic.jpg_200x200.jpg</p></td>
								</tr>
								<tr>
									<td>市场价：</td>
									<td><input class="text-input medium-input" type="text" name="pirce" /></td>
								</tr>
								<tr>
									<td>商品旺旺：</td>
									<td><input class="text-input medium-input" type="text" name="ww" /></td>
								</tr>
								<tr>
									<td>竞拍时间：</td>
									<td><input class="text-input medium-input" type="text" name="pDate" onClick="WdatePicker()"/></td>
								</tr>
								<tr>
									<td>兑换金币：</td>
									<td><input class="text-input medium-input" type="text" name="exchangeGold" /></td>
								</tr>
								<tr>
									<td>剩余数量：</td>
									<td><input class="text-input medium-input" type="text" name="exchangeNum" /></td>
								</tr>
								<tr>
									<td colspan="2"><input class="button" type="submit" value="添加"/></td>
								</tr>
							</table>
							</fieldset>
							<div class="clear"></div>
							<!-- End .clear -->
						</form>
					</div>
					<!-- End #tab1 -->
				</div>
				<!-- End .content-box-content -->
			</div>
			<!-- End .content-box -->

			<div class="clear"></div>

			<div id="footer">
				<small> <!-- Remove this notice or replace it with whatever you want -->
					&#169; Copyright 2009 Your Company | Powered by <a
					href="http://themeforest.net/item/simpla-admin-flexible-user-friendly-admin-skin/46073">Simpla
						Admin</a> | <a href="#">Top</a>
				</small>
			</div>
			<!-- End #footer -->

		</div>
		<!-- End #main-content -->

	</div>
</body>


<!-- Download From www.exet.tk-->
</html>
